package com.jxtti.controller;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;



import com.jxtti.entity.SiteLog;
import com.jxtti.service.SiteLogService;
import com.jxtti.utils.ExceptionUtil;
/**
 * 
 * <br>
 * <b>功能：</b>SiteLogController<br>
 * <b>作者：lwb</b><br>
 * <b>日期：</b> Nov 26, 2015 <br>
 * <b>版权所有：<b>版权所有(C) 2015，<br>
 */ 
@Controller
@RequestMapping("/siteLog") 
public class SiteLogController {
	
	private final static Logger log= Logger.getLogger(SiteLogController.class);
	
	// Servrice start
	@Autowired
	private SiteLogService  siteLogService; 
	
	
	
	
	
	/**
	 * 
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value="/list") 
	public ModelAndView  list(@RequestParam Map<String, Object> data,  SiteLog siteLog, HttpServletRequest request,
			HttpServletResponse response) throws Exception{		
		ModelAndView mav = new ModelAndView();
		try {
			data =  siteLogService.list(data, siteLog);
			mav.addObject("data", data);
			mav.setViewName("/pages/Admin/SiteManager/site_log_list.jsp");
		} catch (Exception e) {
			e.printStackTrace();
			
		}
		return mav;
	}
	
	@RequestMapping(value="/listData") 
	public List<SiteLog>  listData(@RequestParam Map<String, Object> data,  SiteLog siteLog, HttpServletRequest request,
			HttpServletResponse response) throws Exception{		
		List<SiteLog>  lst = this.siteLogService.queryAll(data);
		return lst;
	}
	
	/**
	 * 点击添加跳转到增加界面
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addInterface")
	@ResponseBody
	public ModelAndView addInterface(@RequestParam Map<String, Object> data,
			HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		try {
			mav.addObject("data", data);
			mav.setViewName("/pages/siteLog/add.jsp");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
	}
	
	
	
	
	/**
	 * 添加或修改数据
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "/save")
	@ResponseBody
	public Map<String,Object> save(@RequestParam Map<String, Object> data,
			SiteLog  siteLog, HttpServletRequest request,
			HttpServletResponse response) throws Exception{

		ModelAndView mav = new ModelAndView();
		try {
			// 保存数据
			//User user = AuthUtil.getUserInfo(request);
			//disStandard.setOperPerson(user.getUserName());
			int exeCount = siteLogService.add(siteLog);
			if (exeCount > 0) {
				data.put("success", true);
			} else {
				data.put("success", false);
			}
		} catch (Exception e) {
			data.put("success", false);
			data.put("error", ExceptionUtil.createStackTrackMessage(e));
			e.printStackTrace();
		}
		return data;
	}
	
	
	
	
	/**
	 * 点击修改跳转到增加界面
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/updateInterface")
	@ResponseBody
	public ModelAndView updateInterface(@RequestParam Map<String, Object> data,
			HttpServletRequest request, SiteLog  siteLog,
			HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		try {
			siteLog = siteLogService.querySiteLogById(siteLog);
		
			data.put("siteLog", siteLog);
			mav.addObject("data", data);
			mav.setViewName("/pages/siteLog/update.jsp");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
	}
	
	
	
	
	
	
	
	/**
	 * 修改信息
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> update(@RequestParam Map<String, Object> data,
			SiteLog  siteLog, HttpServletRequest request,
			HttpServletResponse response) {
		try {
		//	User user = AuthUtil.getUserInfo(request);
		//	siteLog.setOperPerson(user.getUserName());
			// 修改
			SiteLog siteLogTem=siteLogService.querySiteLogById(siteLog);
			siteLog.setCreater(siteLogTem.getCreater());

			int exeCount = siteLogService.update( siteLog);
			if (exeCount > 0) {
				data.put("success", true);
			} else {
				data.put("success", false);
			}
		} catch (Exception e) {
			data.put("success", false);
			data.put("error", ExceptionUtil.createStackTrackMessage(e));
			e.printStackTrace();
		}
		return data;
	}
	
	

/**
	 * 删除信息
	 * 
	 * @param data
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Map<String, Object> delete(@RequestParam Map<String, Object> data,
			SiteLog  siteLog, HttpServletRequest request,
			HttpServletResponse response) {
		try {
		//	User user = AuthUtil.getUserInfo(request);
		//	siteLog.setOperPerson(user.getUserName());
		
			 siteLog=siteLogService.querySiteLogById( siteLog);
			int exeCount = siteLogService.update(siteLog);
			if (exeCount > 0) {
				data.put("success", true);
			} else {
				data.put("success", false);
			}
		} catch (Exception e) {
			data.put("success", false);
			data.put("error", ExceptionUtil.createStackTrackMessage(e));
			e.printStackTrace();
		}
		return data;
	}

}
